package com.acwing.chapter3;

import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author anan
 * @create 2021-08-02 22:53
 */
public class Dandiaozhan {
    private static int M = 100010;
    private static int[] stk = new int[M];
    private static int tt;

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] str1 = reader.readLine().split(" ");
        int N = Integer.parseInt(str1[0]);
        int x;
        String[] str2 = reader.readLine().split(" ");
        for (int i = 0; i < N; i++) {
            x = Integer.parseInt(str2[i]);
            while (stk[tt] >= x) tt--;
            if (stk[tt] < x && tt > 0){
                System.out.print(stk[tt] + " ");
            }
            else System.out.print(-1 + " ");
            stk[++tt] = x;
        }

    }

}
